/*----------------------------------------------------------------
 *  Author:        Funing Teng
 *  Written:       02/10/2014
 *  Last updated:  02/10/2014
 *
 *  Person who has a membership within the system. 
 *  The member can earn and apply the reward credit.
 *
 *----------------------------------------------------------------*/

package JavaSource;
import java.io.Serializable;
import java.util.*;

/**
 *
 * @author Funing Teng
 * @version 1.0
 */
public class Member extends Customer implements Serializable {
    
    // Attribute
    private int status;
    private int rewardCredits;
    private LinkedList<Order> orderHistory; 
    private LinkedList<Payment> paymentHistory;
    private String[] cardInfo = new String[3];

    public LinkedList<Payment> getPaymentHistory() {
        return paymentHistory;
    }

    public void setPaymentHistory(LinkedList<Payment> paymentHistory) {
        this.paymentHistory = paymentHistory;
    }

    public LinkedList<Order> getOrderHistory() {
        return orderHistory;
    }

    public void setOrderHistory(LinkedList<Order> orderHistory) {
        this.orderHistory = orderHistory;
    }

   

    // Constructor
    public Member( String name, String email, String deliveryAddress, String phoneNumber, boolean paymentMethod, String password,
            int status, int rewardCredits,String card) {
        super(name,email,deliveryAddress,phoneNumber,paymentMethod, password);
        this.status = status;
        this.orderHistory = new LinkedList<Order>();
        this.paymentHistory = new LinkedList<Payment>();
        this.rewardCredits = rewardCredits;
        this.cardInfo[0]=card;
    }
    
    // Method
    public int getStatus() {
        return status;
    }

    public void setStatus(int status) {
        this.status = status;
    }

    public int getRewardCredits() {
        return rewardCredits;
    }

    public void setRewardCredits(int rewardCredits) {
        this.rewardCredits = rewardCredits;
    }
    
    public String[] getCardInfo() {
        return cardInfo;
    }

    public boolean setCardInfo(String card) {
        for(int i = 0; i < cardInfo.length; i++){
            if(cardInfo[i] == null){
                cardInfo[i] = card;
                
                return true;
            }
        }
        return false;
    }

 
    @Override
    public boolean equals(Object obj) {
        if (obj == null) {
            return false;
        }
        if (getClass() != obj.getClass()) {
            return false;
        }
        final Member other = (Member) obj;
        if (this.status != other.status) {
            return false;
        }
        if (this.rewardCredits != other.rewardCredits) {
            return false;
        }
        return true;
    }
     public void updateRewardCredit(double price, int previouscredit, int creditused)
    {
        int i=previouscredit-creditused+ (int)price;
        setRewardCredits(i);
    }
    
}
